defmodule RedisLib do
	@moduledoc false
	require Logger

	def start_redis_app() do
		Application.put_env(:redix_pool, :redis_url, AppConfigure.fetch(:redis_url))
		Application.ensure_started(:redix_pool, :permanent)
	end

	def execute(command) do
		RedixPool.command(command)
	end

	def execute!(command) do
		RedixPool.command!(command)
	end

	def execute(order, key, value) do
		RedixPool.command([order, key, value])
	end

	def set!(key, value) do
		RedixPool.command!(["SET", key, value])
	end

	def get(key) do
		RedixPool.command(["GET", key])
	end

	def hs_get(key, field) do
		case RedixPool.command(["HGET", key, field]) do
			{:ok, v} ->
				v
			{:error, reason} ->
				Logger.error("hsget Error, reason:#{inspect(reason)}")
				nil
		end
	end
	def hs_set!(key, field, value) do
		RedixPool.command!(["HSET", key, field, value])
	end

	def hs_del!(key, field) do
		RedixPool.command!(["HDEL", key, field])
	end

	def incr_by!(key, value) do
		RedixPool.command!(["INCR", key, value])
	end

	def decr_by!(key, value) do
		incr_by!(key, -value)
	end

	def hs_incrby!(key, field, value) do
		RedixPool.command!(["HINCRBY", key, field, value])
	end

	def hs_decrby!(key, field, value) do
		hs_incrby!(key, field, -value)
	end

	def pipeline([]) do
		{:ok, []}
	end
	def pipeline(list) do
		RedixPool.pipeline(list)
	end
	def pipeline!([]) do
		:ok
	end
	def pipeline!(list) do
		RedixPool.pipeline!(list)
	end

	def hs_get_all(key) do
		RedixPool.command(["HGETALL", key])
	end

	def hs_inc_command(table, k, v) do
		["HINCRBY", table, k, v]
	end

	def get_command(k) do
		["GET", k]
	end

	def set_command(k, v) do
		["SET", k, v]
	end

	def hs_set_command(key, field, value) do
		["HMSET", key, field, value]
	end

	def hs_get_command(key, field) do
		["HGET", key, field]
	end

	def hs_del_command(key, field) do
		["HDEL", key, field]
	end



end
